<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 内容管理模块
 */
class Contents extends Admin_Controller {
	
	function __construct()
	{
	    parent::__construct();
            $this->load->model('cate_model');
            $this->load->model('content_model');
            $this->load->model('partner_model');
            $this->load->model('banner_model');
            $this->load->model('video_model');
	}
        //单页管理
	public function index()
	{
            $where = array();
            $where['type'] = 1;
            $keyword = trim($_GET['q']);
            $like = $keyword ? $keyword : '';
            //分页
            $getcount = $this->content_model->getCount($where,$like);
            $navigation_position = 'outside';
            $records_per_page = 10;
            $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
            //$this->xpage->reverse(true);
            $this->xpage->records($getcount);
            $this->xpage->records_per_page($records_per_page);
            $this->xpage->labels("<<", ">>");
            $list = $this->content_model->getList($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page,$like);
            //------------------
            $this->template->assign('Total',$getcount);
            $this->template->assign('showpage',$this->xpage->render(true));
            $this->template->assign('list',$list);
            $this->template->assign('segment_p','index');
            $this->template->load('contents/index');
        }
        
        //单页添加
        public function page_add(){
            if($_POST){
                $mssage = array();
                $cate_id	= trim($_POST['cate_id']);
                $title		= trim($_POST['title']);
                $code		= trim($_POST['code']);
                $thumb		= trim($_POST['thumb']);
                $summary	= trim($_POST['summary']);
                $content	= trim($_POST['content']);
                $status		= trim($_POST['status']);

                if(!$cate_id){
                        $mssage['info']	  = '请选择分类';
                        $mssage['status'] = 0;
                        $mssage['url']	  = '';
                        echo json_encode($mssage);exit;
                }
                if(!$title){
                        $mssage['info']	  = '页面名称必须填写';
                        $mssage['status'] = 0;
                        $mssage['url']	  = '';
                        echo json_encode($mssage);exit;
                }
                if(!$code){
                        $mssage['info']	  = '页面识标必须填写';
                        $mssage['status'] = 0;
                        $mssage['url']	  = '';
                        echo json_encode($mssage);exit;
                }

                $chk = $this->content_model->getByCode($code);
                if($chk['code']!=''){
                                $mssage['info']	  = '标识重复，操作失败';
                                $mssage['status'] = 0;
                                $mssage['url']	  = '';
                                echo json_encode($mssage);exit;
                }

                $data = array();
                $data['cate_id'] = $cate_id;
                $data['title'] = $title;
                $data['code'] = $code;
                $data['thumb'] = $thumb;
                $data['summary'] = $summary;
                $data['content'] = $content;
                $data['status'] = $status;
                $data['type'] = 1;
                $data['author'] = $this->session->userdata('username');
                $data['create_time'] = time();
                $data['update_time'] = time();
                $result = $this->content_model->insert($data);
                   if($result){
                                //update_cache('menu');
                           $mssage['info']	  = '添加成功';
                                $mssage['status'] = 1;
                                $mssage['url']	  = site_url('contents/index');
                                echo json_encode($mssage);exit;
                   }else{
                            $mssage['info']	  = '修改失败';
                                $mssage['status'] = 0;
                                $mssage['url']	  = site_url('contents/index');
                                echo json_encode($mssage);exit;
                   }
            }
            $where = array();
            $where['group'] = 'onepage';
            $catelist = $this->cate_model->get_content_list($where);
            $catelist = $this->cate_model->tree($catelist);
            $this->template->assign('catelist',$catelist);
            $this->template->assign('segment_p','index');
            $this->template->load('contents/page_add');
        }
        
        public function page_edit()
	{	
		
		$id	   = intval($_GET['id']);
		if(!$id){
		redirect('contents/index');
		}
		if($_POST){
			$mssage = array();
			$id	= intval($_POST['id']);
			if(!$id){
			redirect('contents/index');
			}
			$kcode		= trim($_POST['kcode']);
			$cate_id	= trim($_POST['cate_id']);
			$title		= trim($_POST['title']);
			$code		= trim($_POST['code']);
			$thumb		= trim($_POST['thumb']);
			$summary	= trim($_POST['summary']);
			$content	= trim($_POST['content']);
			$status		= trim($_POST['status']);
			
			if(!$cate_id){
				$mssage['info']	  = '请选择分类';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			if(!$title){
				$mssage['info']	  = '页面名称必须填写';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			if(!$code){
				$mssage['info']	  = '页面识标必须填写';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			
			if($kcode!=$code){
				$chk = $this->content_model->getByCode($code);
				if($chk['code']!=''){
						$mssage['info']	  = '标识重复，操作失败';
						$mssage['status'] = 0;
						$mssage['url']	  = '';
						echo json_encode($mssage);exit;
				}
			}
			
			
			$data = array();
			$data['cate_id'] = $cate_id;
			$data['title'] = $title;
			$data['code'] = $code;
			if($thumb){
			$data['thumb'] = $thumb;
			}
			$data['summary'] = $summary;
			$data['content'] = $content;
			$data['status'] = $status;
			$data['type'] = 1;
			$data['author'] = $this->session->userdata('username');
			$data['update_time'] = time();
			$result = $this->content_model->update($data,$id);
			   if($result){
					//update_cache('menu');
				   $mssage['info']	  = '添加成功';
					$mssage['status'] = 1;
					$mssage['url']	  = site_url('contents/index');
					echo json_encode($mssage);exit;
			   }else{
				    $mssage['info']	  = '修改失败';
					$mssage['status'] = 0;
					$mssage['url']	  = site_url('contents/index');
					echo json_encode($mssage);exit;
			   }
	   
			
			
			
		}
		
		$item = $this->content_model->Get($id);
		$where = array();
		$where['group'] = 'onepage';
		$catelist = $this->cate_model->get_content_list($where,$where_or);
		$catelist = $this->cate_model->tree($catelist);
		//print_r($catelist[0]);
		$this->template->assign('catelist',$catelist);
		//重定义页面
		$this->template->assign('segment_p','index');
		$this->template->assign('item',$item);
		$this->template->load('contents/page_edit');
	}
        
        public function page_setstatus()
	{	
		
		if($_GET){
			$mssage = array();
			$id	   = trim($_GET['ids']);
			$status = trim($_GET['status']);
			$result = $this->content_model->setstatus($status,$id);
			   if($result){
				    if($status==1){
					$mssage['info']	  = '禁用成功';
					}else{
					$mssage['info']	  = '启用成功';
					}
					$mssage['status'] = 1;
					$mssage['url']	  = $_SERVER['HTTP_REFERER'];
					echo json_encode($mssage);exit;
			   }else{
				    $mssage['info']	  = '操作失败';
					$mssage['status'] = 0;
					$mssage['url']	  = $_SERVER['HTTP_REFERER'];
					echo json_encode($mssage);exit;
			   }
			   
		}	
	
	}
	
	public function page_remove()
	{
		$id	   = intval($_GET['id']);
		if(!$id){
		redirect('contents/index');
		}
		
			   $result = $this->content_model->dalete($id);
			    if($this->db->affected_rows()){
				    $mssage['info']	  = '删除成功';
					$mssage['status'] = 1;
					$mssage['url']	  = site_url('contents/articles');
					echo json_encode($mssage);exit;
			   }else{
				    $mssage['info']	  = '删除失败';
					$mssage['status'] = 0;
					$mssage['url']	  = site_url('contents/articles');
					echo json_encode($mssage);exit;
			   }
	
	}
        
        public function articles()
	{
		$keyword = trim($_GET['q']);
		$like = $keyword ? $keyword : '';
		$where = array();
		$where['type'] = 0;
		//分页
		$getcount = $this->content_model->getCount($where,$like);
		$navigation_position = 'outside';
		$records_per_page = 10;
		$this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
		//$this->xpage->reverse(true);
		$this->xpage->records($getcount);
		$this->xpage->records_per_page($records_per_page);
		$this->xpage->labels("<<", ">>");
		$list = $this->content_model->getList($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page,$like);
		$this->template->assign('Total',$getcount);
		$this->template->assign('showpage',$this->xpage->render(true));
		$this->template->assign('list',$list);
		$this->template->load('contents/articles');
	}
        
        public function articles_add()
	{	
		if($_POST){
			$mssage = array();
			
			$cate_id	= trim($_POST['cate_id']);
			$title		= trim($_POST['title']);
			$code		= trim($_POST['code']);
			$thumb		= trim($_POST['thumb']);
			$summary	= mb_substr($this->trimall(strip_tags($_POST['content'])),0,100,'utf-8');
			$content	= trim($_POST['content']);
			$status		= trim($_POST['status']);
			$out_link   = trim($_POST['out_link']);
			if(!$cate_id){
				$mssage['info']	  = '请选择分类';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			if(!$title){
				$mssage['info']	  = '页面名称必须填写';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			/*
			if(!$code){
				$mssage['info']	  = '页面识标必须填写';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			
			$chk = $this->content_model->getByCode($code);
			if($chk['code']!=''){
					$mssage['info']	  = '标识重复，操作失败';
					$mssage['status'] = 0;
					$mssage['url']	  = '';
					echo json_encode($mssage);exit;
			}
			*/
			$data = array();
			$data['cate_id'] = $cate_id;
			$data['title'] = $title;
			$data['code'] = $code;
			$data['thumb'] = $thumb;
			$data['summary'] = $summary;
			$data['content'] = $content;
			$data['status'] = $status;
			$data['type'] = 0;
			$data['author'] = $this->session->userdata('username');
			$data['create_time'] = time();
			$data['update_time'] = time();
			$data['out_link'] = $out_link;
			$result = $this->content_model->insert($data);
			   if($result){
					//update_cache('menu');
				   $mssage['info']	  = '添加成功';
					$mssage['status'] = 1;
					$mssage['url']	  = site_url('contents/articles');
					echo json_encode($mssage);exit;
			   }else{
				    $mssage['info']	  = '修改失败';
					$mssage['status'] = 0;
					$mssage['url']	  = site_url('contents/articles');
					echo json_encode($mssage);exit;
			   }
	   
			
			
			
		}
		
		$where = array();
		$where['group !='] = 'onepage';
		$where['group  !='] = 'helppage';
		$catelist = $this->cate_model->get_content_List($where);
		$catelist = $this->cate_model->tree($catelist);
		//print_r($catelist[0]);
		$this->template->assign('catelist',$catelist);
		//重定义页面
		$this->template->assign('segment_p','articles');
		$this->template->load('contents/articles_add');
	}
	public function articles_edit()
	{	
		
		$id	   = intval($_GET['id']);
		if(!$id){
		redirect('contents/articles');
		}
		if($_POST){
			$mssage = array();
			$id	= intval($_POST['id']);
			if(!$id){
			redirect('contents/articles');
			}
			$kcode		= trim($_POST['kcode']);
			$cate_id	= trim($_POST['cate_id']);
			$title		= trim($_POST['title']);
			$code		= trim($_POST['code']);
			if(trim($_REQUEST['thumb'])){
			$thumb = trim($_REQUEST['thumb']);
			}
			$summary	= mb_substr($this->trimall(strip_tags($_POST['content'])),0,100,'utf-8');
			$content	= trim($_POST['content']);
			$status		= trim($_POST['status']);
			
			if(!$cate_id){
				$mssage['info']	  = '请选择分类';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			if(!$title){
				$mssage['info']	  = '页面名称必须填写';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			/*
			if(!$code){
				$mssage['info']	  = '页面识标必须填写';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			
			if($kcode!=$code){
				$chk = $this->content_model->getByCode($code);
				if($chk['code']!=''){
						$mssage['info']	  = '标识重复，操作失败';
						$mssage['status'] = 0;
						$mssage['url']	  = '';
						echo json_encode($mssage);exit;
				}
			}
			*/
			
			$data = array();
			$data['cate_id'] = $cate_id;
			$data['title'] = $title;
			$data['code'] = $code;
			if(!empty($thumb)){
			$data['thumb'] = $thumb;
			}else{
			}
			$data['summary'] = $summary;
			$data['content'] = $content;
			$data['status'] = $status;
			$data['author'] = $this->session->userdata('username');
			$data['update_time'] = time();
			$result = $this->content_model->update($data,$id);
			   if($result){
					//update_cache('menu');
				   $mssage['info']	  = '添加成功';
					$mssage['status'] = 1;
					$mssage['url']	  = site_url('contents/articles');
					echo json_encode($mssage);exit;
			   }else{
				    $mssage['info']	  = '修改失败';
					$mssage['status'] = 0;
					$mssage['url']	  = site_url('contents/articles');
					echo json_encode($mssage);exit;
			   }
	   
			
			
			
		}
		
		$item = $this->content_model->Get($id);
		$where = array();
		$where['group !='] = 'onepage';
		$catelist = $this->cate_model->get_content_List($where);
                
		$catelist = $this->cate_model->tree($catelist);
		//print_r($catelist[0]);
		$this->template->assign('catelist',$catelist);
		//重定义页面
		$this->template->assign('segment_p','articles');
		$this->template->assign('item',$item);
		$this->template->load('contents/articles_edit');
	}
        //视频模块
	public function videos()
	{
			$where = array();
			//分页
			$getcount = $this->video_model->get_count($where);
			$navigation_position = 'outside';
			$records_per_page = 10;
			$this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
			$this->xpage->records($getcount);
			$this->xpage->records_per_page($records_per_page);
			$this->xpage->labels("<<", ">>");

			$list = $this->video_model->get_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
			//重定义页面
			$this->template->assign('segment_p','videos');
			//------------------
			$this->template->assign('Total',$getcount);
			$this->template->assign('showpage',$this->xpage->render(true));
			$this->template->assign('list',$list);
			$this->template->load('contents/videos');
	}

	public function videos_add()
	{
		if($_POST){
			$mssage = array();
			$title	= trim($_POST['title']);
			$authorid	= 13132;
			$img_url = trim($_POST['img_url']);
			$desc	= trim($_POST['desc']);
			$status		= trim($_POST['status']);
			$link_url   = trim($_POST['link_url']);
			if(!$title){
				$mssage['info']	  = '页面名称必须填写';
				$mssage['status'] = 0;
				$mssage['url']	  = '';
				echo json_encode($mssage);exit;
			}
			$data = array();
			$data['title'] = $title;
			$data['img_url'] = $img_url;
			$data['desc'] = $desc;
			$data['status'] = $status;
			$data['authorid'] = $authorid;
			$data['create_time'] = time();
			$data['link_url'] = $link_url;
			$data['salt'] = random_string('alnum', 6);
			$result = $this->video_model->insert($data);
			if($result){
				//update_cache('menu');
				$mssage['info']	  = '添加成功';
				$mssage['status'] = 1;
				$mssage['url']	  = site_url('contents/videos');
				echo json_encode($mssage);exit;
			}else{
				$mssage['info']	  = '修改失败';
				$mssage['status'] = 0;
				$mssage['url']	  = site_url('contents/videos');
				echo json_encode($mssage);exit;
			}
		}
		//重定义页面
		$this->template->assign('segment_p','videos');
		$this->template->load('contents/videos_add');
	}

	public function videos_edit()
	{

		$id	   = intval($_GET['id']);
		if(!$id){
			redirect('contents/videos');
		}
		if($_POST){
			$mssage = array();
			$title	= trim($_POST['title']);
			$authorid	= 13132;
			$img_url = trim($_POST['img_url']);
			$desc	= trim($_POST['desc']);
			$status		= trim($_POST['status']);
			$link_url   = trim($_POST['link_url']);

			$data = array();
			$data['title'] = $title;
			$data['img_url'] = $img_url;
			$data['desc'] = $desc;
			$data['status'] = $status;
			$data['authorid'] = $authorid;
			$data['create_time'] = time();
			$data['link_url'] = $link_url;
			$result = $this->video_model->update($data,$id);
			if($result){
				//update_cache('menu');
				$mssage['info']	  = '添加成功';
				$mssage['status'] = 1;
				$mssage['url']	  = site_url('contents/videos');
				echo json_encode($mssage);exit;
			}else{
				$mssage['info']	  = '修改失败';
				$mssage['status'] = 0;
				$mssage['url']	  = site_url('contents/videos');
				echo json_encode($mssage);exit;
			}
		}

		$item = $this->video_model->Get($id);
		//重定义页面
		$this->template->assign('segment_p','videos');
		$this->template->assign('item',$item);
		$this->template->load('contents/videos_edit');
	}

	public function videos_setstatus()
	{

		if($_GET){
			$mssage = array();
			$id	   = trim($_GET['ids']);
			$status = trim($_GET['status']);
			$result = $this->video_model->setstatus($status,$id);
			if($result){
				if($status==1){
					$mssage['info']	  = '禁用成功';
				}else{
					$mssage['info']	  = '启用成功';
				}
				$mssage['status'] = 1;
				$mssage['url']	  = $_SERVER['HTTP_REFERER'];
				echo json_encode($mssage);exit;
			}else{
				$mssage['info']	  = '操作失败';
				$mssage['status'] = 0;
				$mssage['url']	  = $_SERVER['HTTP_REFERER'];
				echo json_encode($mssage);exit;
			}

		}

	}

	public function videos_remove()
	{
		$id	   = intval($_GET['id']);
		if(!$id){
			redirect('contents/index');
		}

		$result = $this->video_model->delete($id);
		if($this->db->affected_rows()){
			$mssage['info']	  = '删除成功';
			$mssage['status'] = 1;
			$mssage['url']	  = site_url('contents/videos');
			echo json_encode($mssage);exit;
		}else{
			$mssage['info']	  = '删除失败';
			$mssage['status'] = 0;
			$mssage['url']	  = site_url('contents/videos');
			echo json_encode($mssage);exit;
		}

	}
        //去空格
        function trimall($str)
        {
                $qian=array(" ","　","\t","\n","\r","&nbsp;");
                $hou=array("","","","","","");
                return str_replace($qian,$hou,$str); 
        }
        
        //合作机构列表
        function partner(){
            $where = array();
            $like = '';
            //分页
            $getcount = $this->partner_model->get_count($where,$like);
            $navigation_position = 'outside';
            $records_per_page = 10;
            $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
            //$this->xpage->reverse(true);
            $this->xpage->records($getcount);
            $this->xpage->records_per_page($records_per_page);
            $this->xpage->labels("<<", ">>");

            $list = $this->partner_model->get_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page,$like);

            foreach($list as $key=>$val){
               $list[$key]['create_time'] = date('Y-m-d H:i:s',$val['create_time']);
            }
            //重定义页面
            $this->template->assign('segment_p','partner');
            //------------------
            $this->template->assign('Total',$getcount);
            $this->template->assign('showpage',$this->xpage->render(true));
            $this->template->assign('list',$list);
            $this->template->load('contents/partner');
        }
        
        function partner_add()
	{
            if($_POST){
                $data = array();
                $data['name'] = trim($_POST['name']);
                $data['website'] = trim($_POST['website']);
                $data['logo'] = trim($_POST['logo']);
                $data['description'] = trim($_POST['description']);
                $data['sort'] = trim($_POST['sort']);
                $data['is_show'] = trim($_POST['is_show']);
                $data['create_time'] = time();
                $result = $this->partner_model->insert($data);
                if($result){
                    $mssage['info']	  = '添加成功';
                    $mssage['status'] = 1;
                    $mssage['url']	  = site_url('contents/partner');
                    echo json_encode($mssage);exit;
                }else{
                    $mssage['info']	  = '操作失败';
                    $mssage['status'] = 0;
                    $mssage['url']	  = site_url('contents/partner');
                    echo json_encode($mssage);exit;
                }

            }
            //重定义页面
            $this->template->assign('segment_p','partner');
            $this->template->load('contents/partner_add');
	}
	
	public function partner_edit()
	{
            $id = intval($_GET['id']);
            if(!$id){
                redirect('contents/partner');
            }
            if($_POST){
                $id = $_POST['id'];
                $data = array();			
                if(trim($_POST['logo'])){
                    $data['logo'] = trim($_POST['logo']);
                }
                $data['name'] = trim($_POST['name']);
                $data['website'] = trim($_POST['website']);
                $data['logo'] = trim($_POST['logo']);
                $data['description'] = trim($_POST['description']);
                $data['sort'] = trim($_POST['sort']);
                $data['is_show'] = trim($_POST['is_show']);
                $data['create_time'] = time();
                $result = $this->partner_model->update($data,$id);
                if($result){
                         $mssage['info']	  = '修改成功';
                             $mssage['status'] = 1;
                             $mssage['url']	  = site_url('contents/partner');
                             echo json_encode($mssage);exit;
                }else{
                         $mssage['info']	  = '操作失败';
                             $mssage['status'] = 0;
                             $mssage['url']	  = site_url('contents/partner');
                             echo json_encode($mssage);exit;
                }

            }
            
            $item = $this->partner_model->Get($id);
            //重定义页面
            $this->template->assign('segment_p','partner');
            //------------------
            $this->template->assign('item',$item);
            $this->template->load('contents/partner_edit');
	}
	
	public function partner_del()
	{
            $id	   = intval($_GET['id']);
            if(!$id){
                redirect('contents/partner');
            }

            $result = $this->partner_model->delete($id);
            if($result){
                    $mssage['info']	  = '删除成功';
                    $mssage['status'] = 1;
                    $mssage['url']	  = site_url('contents/partner');
                    echo json_encode($mssage);exit;
            }else{
                    $mssage['info']	  = '删除失败';
                    $mssage['status'] = 0;
                    $mssage['url']	  = site_url('contents/partner');
                    echo json_encode($mssage);exit;
            }
	
	}
        
        function partner_setshow(){
            $id	   = intval($_GET['id']);
            if(!$id){
                redirect('contents/partner');
            }
            $is_show = intval($_GET['show']);
            $data = array();
            $data['is_show'] = $is_show;
            $result = $this->partner_model->update($data,$id);
            if($result){
                    $mssage['info']	  = '更新成功';
                    $mssage['status'] = 1;
                    $mssage['url']	  = site_url('contents/partner');
                    echo json_encode($mssage);exit;
            }else{
                    $mssage['info']	  = '删除失败';
                    $mssage['status'] = 0;
                    $mssage['url']	  = site_url('contents/partner');
                    echo json_encode($mssage);exit;
            }
        }
        //banner图片管理
        function banner(){
            $where = array();
            if(isset($_GET['type']) && $_GET['type']){
                $Type = trim($_GET['type']);
                $where['type'] = $Type;
                $this->template->assign('Type',$Type);
            }
            //分页
            $getcount = $this->banner_model->get_count($where);
            $navigation_position = 'outside';
            $records_per_page = 10;
            $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
            $this->xpage->records($getcount);
            $this->xpage->records_per_page($records_per_page);
            $this->xpage->labels("<<", ">>");

            $list = $this->banner_model->get_list($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
            foreach ($list as $key=>$val){
                $type = $val['type'];
                $list[$key]['type'] = $type == 1 ? "PC端-金融" : ($type == 2 ? "移动端" : ($type == 3 ? "众筹" : ($type == 4 ? "PC端-社区" : ($type == 5 ? "微信-社区" : "移动-贷款"))));
            }
            //重定义页面
            $this->template->assign('segment_p','banner');
            //------------------
            $this->template->assign('Total',$getcount);
            $this->template->assign('showpage',$this->xpage->render(true));
            $this->template->assign('list',$list);
            $this->template->load('contents/banner');
        }
        
        
        //banner图片添加
        function banner_add(){
            if($_POST){
                $data = array();
                $data['type'] = trim($_POST['type']);
                $data['banner_img'] = trim($_POST['banner_img']);
                $data['title'] = trim($_POST['title']);
                $data['banner_link'] = trim($_POST['banner_link']);
                $data['sort'] = trim($_POST['sort']);
                $data['status'] = trim($_POST['status']);
                $data['create_time'] = time();
                
                if($data['type'] == 0){
                    $mssage['info']	  = '请选择图片类型';
                    $mssage['status'] = 0;
                    $mssage['url']	  = '';
                    echo json_encode($mssage);exit;
                }
                
                $result = $this->banner_model->insert($data);
                if($result){
                    $mssage['info']	  = '添加成功';
                    $mssage['status'] = 1;
                    $mssage['url']	  = site_url('contents/banner');
                    echo json_encode($mssage);exit;
                }else{
                    $mssage['info']	  = '操作失败';
                    $mssage['status'] = 0;
                    $mssage['url']	  = site_url('contents/banner');
                    echo json_encode($mssage);exit;
                }

            }
            //重定义页面
            $this->template->assign('segment_p','banner');
            $this->template->load('contents/banner_add');
        }
        //BANNER图片修改
        public function banner_edit()
	{
            $id = intval($_GET['id']);
            if(!$id){
                redirect('contents/banner');
            }
            if($_POST){
                $id = $_POST['id'];
                $data = array();
                $data['type'] = trim($_POST['type']);
                $data['banner_img'] = trim($_POST['banner_img']);
                $data['title'] = trim($_POST['title']);
                $data['banner_link'] = trim($_POST['banner_link']);
                $data['sort'] = trim($_POST['sort']);
                $data['status'] = trim($_POST['status']);
                $result = $this->banner_model->update($data,$id);
                if($result){
                         $mssage['info']	  = '修改成功';
                             $mssage['status'] = 1;
                             $mssage['url']	  = site_url('contents/banner');
                             echo json_encode($mssage);exit;
                }else{
                         $mssage['info']	  = '操作失败';
                             $mssage['status'] = 0;
                             $mssage['url']	  = site_url('contents/banner');
                             echo json_encode($mssage);exit;
                }

            }
            
            $item = $this->banner_model->Get($id);
            //重定义页面
            $this->template->assign('segment_p','banner');
            //------------------
            $this->template->assign('item',$item);
            $this->template->load('contents/banner_edit');
	}
        
        //更新BANNER图片显示状态
        function banner_setstatus(){
            $id	   = intval($_GET['id']);
            if(!$id){
                redirect('contents/banner');
            }
            $status = intval($_GET['status']);
            $data = array();
            $data['status'] = $status;
            $result = $this->banner_model->update($data,$id);
            if($result){
                    $mssage['info']	  = '更新成功';
                    $mssage['status'] = 1;
                    $mssage['url']	  = site_url('contents/banner');
                    echo json_encode($mssage);exit;
            }else{
                    $mssage['info']	  = '删除失败';
                    $mssage['status'] = 0;
                    $mssage['url']	  = site_url('contents/banner');
                    echo json_encode($mssage);exit;
            }
        }
        //问答-设置排序
        function banner_setsort(){
            if($_POST){
                $mssage = array();
                $id    = trim($_POST['id']);
                $sort  = trim($_POST['sort']);
                $data = array();
                $data['sort'] = $sort;
                $result = $this->db->where(array("id"=>$id))->update("tan_banner",$data);
                if($result){
                    $mssage['info']	  = '操作成功';
                    $mssage['status'] = 1;
                    $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                    echo json_encode($mssage);exit;
                }else{
                    $mssage['info']	  = '操作失败';
                    $mssage['status'] = 0;
                    $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                    echo json_encode($mssage);exit;
                }
            }
        }
        
        //删除BANNER图片
        function banner_del(){
            $id	   = intval($_GET['id']);
            if(!$id){
                redirect('contents/banner');
            }

            $result = $this->banner_model->delete($id);
            if($result){
                    $mssage['info']	  = '删除成功';
                    $mssage['status'] = 1;
                    $mssage['url']	  = site_url('contents/banner');
                    echo json_encode($mssage);exit;
            }else{
                    $mssage['info']	  = '删除失败';
                    $mssage['status'] = 0;
                    $mssage['url']	  = site_url('contents/banner');
                    echo json_encode($mssage);exit;
            }
        }
    //公益数据
    function charity(){
        if($_POST){
            $mssage = array();
            $id    = trim($_POST['id']);
            $total_money  = trim($_POST['total_money']);
            $total_count  = trim($_POST['total_count']);
            $total_people  = trim($_POST['total_people']);
            $data = array();
            $data['total_money'] = $total_money;
            $data['total_count'] = $total_count;
            $data['total_people'] = $total_people;
            $result = $this->db->where(array("id"=>$id))->update("tan_charity",$data);
            if($result){
                $mssage['info']	  = '操作成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
        $item = $this->db->query("select * from tan_charity where id = 1 limit 1")->row_array();
        $this->template->assign('segment_p','charity');
        $this->template->assign('item',$item);
        $this->template->load('contents/charity');
    }
}
